"""
无线传输电脑侧代码，使用socket进行局域网内的无线通信通信
"""
import socket
import threading

local_ip = "192.168.75.1"
local_port = 5001


def receiveThread(conn):
    conn.settimeout(10)
    while True:
        try:
            client_data = conn.recv(2)  # 这个就是接收自K210的数据，把它打印出来
            print(client_data)
        except socket.timeout:
            client_data = None
        if not client_data:
            break
    conn.close()
    print("receive thread end")


ip_port = (local_ip, local_port)
sk = socket.socket()
sk.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sk.bind(ip_port)
sk.listen(50)
print("accept now,wait for client")


def server():
    while True:
        conn, addr = sk.accept()
        print("hello client,ip:")
        print(addr)
        t = threading.Thread(target=receiveThread, args=(conn,))
        t.setDaemon(True)
        t.start()


tmp = threading.Thread(target=server(), args=())
tmp.setDaemon(True)
tmp.start()

